using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

using memdb_demo.Interop;
using memdb_demo.Interop.WrapModels;

namespace memdb_demo.Models{
    public partial class OrderMonitorModel{

        public uint Offset {get;set;}

        public uint Size{get;set;}

        

        BizInterfaceWrapper _wrapper = new BizInterfaceWrapper();


        public Result<IList<OrderRecord>> Query(){
            var request = new QueryRequest{
                Offset = this.Offset,
                Size = this.Size
            };

            var response = _wrapper.QueryOrder(request);

            var result = new Result<IList<OrderRecord>> { IsSuccess = response.IsSuccess };
            if (!response.IsSuccess){
                result.ErrorMessage = response.ErrorMessage ==null ? string.Empty : response.ErrorMessage.ToString();
                return  result;
            }
            result.Data = response.Data.Select(d=>new OrderRecord(d.Key,d.Value)).ToList();
            return result;
        }


    }
}